package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManageService;
import com.tanhua.model.domain.FreezeDetail;
import com.tanhua.model.dto.BaseUserInfoDto;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/manage")
public class ManageController {

    @Autowired
    private ManageService manageService;

    @GetMapping("/users")
    public ResponseEntity select(Long id, String nickname, String city,
                                @RequestParam(defaultValue = "10") Integer pagesize,
                                @RequestParam(defaultValue = "1") Integer page) {
        PageResult pr = manageService.select(id, nickname, city, pagesize, page);
        return ResponseEntity.ok(pr);
    }

    @GetMapping("/users/{userID}")
    public ResponseEntity selectOne(@PathVariable("userID") Long id) {
        BaseUserInfoDto dto = manageService.selectOne(id);
        return ResponseEntity.ok(dto);
    }

    @PostMapping("/users/freeze")
    public ResponseEntity freeze(@RequestBody FreezeDetail freezeDetail) {
        manageService.freeze(freezeDetail);
        return ResponseEntity.ok("该账户已被冻结");
    }

    @PostMapping("/users/unfreeze")
    public ResponseEntity unfreeze(@RequestBody Map map) {
        Integer userId = (Integer) map.get("userId");
        manageService.unfreeze(userId);
        return ResponseEntity.ok("账户解冻成功");
    }

    @GetMapping("/videos")
    public ResponseEntity selectVideos(Long uid, @RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "10")Integer pagesize, String sortProp, String sortOrder) {
        PageResult pr = manageService.selectVideos(uid,page,pagesize,sortOrder,sortProp);
        return ResponseEntity.ok(pr);
    }

    @GetMapping("/messages")
    public ResponseEntity allMessages(@RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "10")Integer pagesize,
                                      String sortProp, String sortOrder,Long id,
                                      Long uid,Integer state) {
        PageResult pr = manageService.selectMessages(page,pagesize,sortOrder,sortProp,uid,state);
        return ResponseEntity.ok(pr);
    }


}
